package com.mao.service.impl;

import com.mao.mapper.OrderMapper;
import com.mao.pojo.Order;
import com.mao.pojo.User;
import com.mao.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author 小毛同学
 * @version 1.0
 * @data 2022/3/4 15:15
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Order queryById(int id) {
        Order order = orderMapper.queryById(id);

        String url = "http://userservice/user/"+ order.getUserid();
        User user = restTemplate.getForObject(url, User.class);
        order.setUser(user);

        return order;
    }
}
